package org.dromara.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomPasswordGenerator {
    private static final String[] EMOJIS = {"😀", "😃", "😄", "😁", "😆", "😅", "😂", "🤣", "😊", "😇", "🙂", "🙃", "😉", "😌", "😍", "🥰", "😘", "😗", "😙", "😚", "😋", "😛", "😜", "🤪", "😝", "🤑", "🤗", "🤭", "🤫", "🤔", "🤐", "🤨", "😐", "😑", "😶", "🙄", "😏", "😒", "😬", "🤥", "😌", "🤩", "🥳", "😎", "🤓", "🧐", "😕", "😟", "🙁", "☹️", "😮", "😯", "😲", "😳", "🥺", "😦", "😧", "😨", "😰", "😥", "😢", "😭", "😱", "🤯", "😣", "😖", "😫", "😩", "🥱", "😴", "🤤", "😪", "😵", "🤐", "🥴", "🤢", "🤮", "🤧", "😷", "🤒", "🤕", "🤑", "😈", "👿", "👹", "👺", "🤡", "💩", "👻", "💀", "☠️", "👽", "👾", "🤖", "🎃", "😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾"};
    private static final String SOFTWARE_NAME = "星契";
    private static final String[] GUIDING_SENTENCES = {
            "来星契😃沟通呀", "用星契🥰畅快沟通", "星契😎开启沟通之旅",
            "星契带你🥳欢乐畅聊", "在星契😜随心交流", "星契相伴🤗沟通无限",
            "星契开启😏精彩对话", "用星契😘温暖沟通", "星契让沟通😃更有趣"
    };
    private static final Random random = new Random();

    public static String generatePassword(int length) {
        StringBuilder password = new StringBuilder();
        // 先添加软件名
        password.append(SOFTWARE_NAME);
        length -= SOFTWARE_NAME.length();

        List<Integer> usedSentenceIndices = new ArrayList<>();

        while (length > 0) {
            if (random.nextBoolean() && length >= GUIDING_SENTENCES[0].length()) {
                // 有一半的概率添加引导语句
                int index;
                do {
                    index = random.nextInt(GUIDING_SENTENCES.length);
                } while (usedSentenceIndices.contains(index) && usedSentenceIndices.size() < GUIDING_SENTENCES.length);

                String sentence = GUIDING_SENTENCES[index];
                password.append(sentence);
                length -= sentence.length();

                usedSentenceIndices.add(index);
                if (usedSentenceIndices.size() == GUIDING_SENTENCES.length) {
                    usedSentenceIndices.clear();
                }
            } else {
                // 添加随机表情
                int randomIndex = random.nextInt(EMOJIS.length);
                password.append(EMOJIS[randomIndex]);
                length--;
            }
        }

        return password.toString();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            int passwordLength = 60;
            String password = generatePassword(passwordLength);
            System.out.println("生成的口令是: " + password);
        }
    }
}
